<?php
require_once 'ViolationView.php';
	class ViolationManager{
	
		public function validate($snum,$dateViolation,$nature,$actionTaken,$dateReported){
			if(is_numeric($snum)&&($dateViolation!=""||$dateViolation!=null)&&($nature!=""||$nature!=null)&($dateReported!=""||$dateReported!=null)){
						return true;
					}else{
						return false;
				}
		
		}
		
		public function insertViolation($snum,$dateViolation,$nature,$actionTaken,$dateReported){	
			$conn=oci_connect("naiad","1234","localhost/XE");
			if(!$conn){
				$err[] = "Connection error!". var_dump(oci_error());
				echo '<script> alert("'.$err.'") </script>';
				die();
				oci_close($conn);
			}
			else{
				$stvio = oci_parse($conn,"insert into violation(violationno,studentno,dateviolation,nature,actiontaken,datereported) values(violation_seq.nextval,:studentno,:dateviolation,:nature,:actiontaken,:datereported)");
				oci_bind_by_name($stvio, ":studentno", $snum);
				oci_bind_by_name($stvio, ":dateviolation", $dateViolation);
				oci_bind_by_name($stvio, ":nature", $nature);
				oci_bind_by_name($stvio, ":actiontaken", $actionTaken);
				oci_bind_by_name($stvio, ":datereported", $dateReported);

				$exec1 = oci_execute($stvio);
				if($exec1==true){
					return 1;
				}
				oci_commit($conn);
				//oci_free_statement($stid);
				oci_close($conn);
			}	
		}		
	}//class
?>
